﻿using MediatR;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.CJL.Domain;
using System.CJL.API.DTO;
using System.CJL.Domain.DTO;
using System.CJL.API.Application.Command.StorageCommand;
using Azure.Core;


namespace System.CJL.API.Controllers
{
	/// <summary>
	/// 入库管理
	/// </summary>
	[Route("api/[controller]/[action]")]
	[ApiController]
	public class StoragesController : ControllerBase
	{
		IMediator _mediator;
        public StoragesController(IMediator mediator)
        {
            _mediator=mediator;
        }

        /// <summary>
        /// 显示仓入库信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<PageDTO<Storage>>> StoragesShow([FromQuery] StorageShowCommand request)
        {
            ApiResult<PageDTO<Storage>> result = new ApiResult<PageDTO<Storage>>();
            try
            {
                result.Data = await _mediator.Send(request);
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Code = -1;
                throw;
            }
            return result;
        }

        /// <summary>
        /// 全部入库信息（可做下拉列表）
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<PageDTO<Storage>>> StorageList()
        {
            ApiResult<PageDTO<Storage>> result = new ApiResult<PageDTO<Storage>>();
            try
            {
                result.Data = await _mediator.Send(new StorageListCommand());
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Code = -1;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 入库添加
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> StorageAdd(StorageAddCommand t)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Data=await _mediator.Send(t);
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Code = -1;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 入库返填
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<Storage>> StoragesMondel([FromQuery] StorageMondelCommand request)
        {
            ApiResult<Storage> result = new ApiResult<Storage>();
            try
            {
                result.Data = await _mediator.Send(request);
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Code = -1;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 入库修改
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> StorageUpdate(StorageUpdateCommand t)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Data = await _mediator.Send(t);
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Code = -1;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 入库删除
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> StorageDelete(StorageDeleteCommand t)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Data = await _mediator.Send(t);
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Code = -1;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 入库批量删除
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> StorageDeletePi(StorageDeletePiCommand t)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Data = await _mediator.Send(t);
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Code = -1;
                throw;
            }
            return result;
        }


        /// <summary>
        /// 根据采购编号查询入库信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<Storage>>> StoragesPurchaseNumberShow([FromQuery] StoragesPurchaseNumberShowCommand request)
        {
            ApiResult<List<Storage>> result = new ApiResult<List<Storage>>();
            try
            {
                result.Data = await _mediator.Send(request);
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Code = -1;
                throw;
            }
            return result;
        }

    
		/// <summary>
		/// 入库修改状态
		/// </summary>
		/// <param name="t"></param>
		/// <returns></returns>
		[HttpPost]
		public async Task<ApiResult<int>> StorageUpdateStatus(StorageUpdateStatusCommand request)
		{
			ApiResult<int> result = new ApiResult<int>();
			try
			{
				result.Data = await _mediator.Send(request);
			}
			catch (Exception ex)
			{
				result.Message = ex.Message;
				result.Code = -1;
				throw;
			}
			return result;
		}

	}
}
